#@head() 
#@header()
<title>融资需求管理</title>
#@aside("custser")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>

<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">客服分配</a></li>
              <!--<li class="active"><a href="#tab_2" data-toggle="tab" aria-expanded="false">还款管理</a></li>-->
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
				<div class="box-body">
					<table id="example1" style="" class="table table-striped">
						<tbody>
							<tr>
								<th align="right" style="width:100px">选择客服</th>
								<td style="width:50%;">
									<select id="allowBid" class="form-control select2 select2-hidden-accessible" multiple="" data-placeholder="请选择客服" style="width:100%;" tabindex="-1" aria-hidden="true">
									</select>
								</td>
								<td><button type="submit" id="submit" style="float:left;margin-left:10px;" class="btn btn-info ">提交</button></td>
							</tr>
						</tbody>
					</table>

					<table  id="example1" class="table table-striped">
						<thead>
							<tr>
								<th>ID</th>
								<th>分配时间</th>
								<th>客服</th>
								<th>操作人</th>
							</tr>
						</thead>
						<tbody id="userlist">
							
						</tbody>
					</table>
					<div class="box-footer clearfix">
					  <ul class="pagination pagination-sm no-margin pull-right">
						<li id="userlist1"><a href="#">首页</a></li>
						<li id="userlist2"><a href="#">上一页</a></li>
						<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
						<li id="userlist3"><a href="#">下一页</a></li>
						<li id="userlist4"><a href="#">尾页</a></li>
					  </ul>
					</div>
				</div>
              </div>
            </div>
            <!-- /.tab-content -->
          </div>
		  
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${id}</td>
		<td>${create_time}</td>
		<td>${agents_real_name}</td>
		<td>${creater_real_name}</td>
	</tr>
</script>
<script>
$(document).ready(function(){
	$("#allowBid").select2();
	$.getJSON("/staff/list?token=#(session.token??)&page=1&size=999&role=agent*agent_leader*agent_manager", function(userli) {
		$.each(userli.data.page.list, function(i, item){ 
			$("#allowBid").append("<option value='"+item.user_id+"'>"+item.real_name+"</option>");
		});
	});	
	$("#submit").click(function() {
		var agentlist = $("#allowBid").val();
		if(agentlist==null){
			layer.msg('请选择客服！', {icon : 2});
		}else{
			layer.confirm('是否确认提交？', {btn : [ '确认', '取消' ]}, function() {
				ajax("#(path)/allot_log?token=#(session.token??)&value="+agentlist,{},function(data){
					console.log(data);
					if(data.code=='success'){
						layer.msg(data.msg, {icon:1},function(){
							location.href="#(path)/admin/page/custser-allot"
						});
					}else if(data.code=='error'){
						layer.msg(data.msg, {icon : 2});
					}
				});
			}, function() {
				layer.msg('已取消！', {icon : 1});
			});
		}
	});
	var totalPage = 1;
	var pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber);
	$("#userlist5").html(pageNumber);

	$("#userlist1").click(function(){
		$("#userlist").empty();
		pageNumber = 1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
	});
	$("#userlist2").click(function(){
		if(pageNumber==1){
			alert("当前页是首页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist3").click(function(){
		if(pageNumber==totalPage){
			alert("当前页是尾页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber +1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist4").click(function(){
		$("#userlist").empty();
		pageNumber = totalPage;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
	});
	$("#seachuser").click(function(){
		pageNumber = 1;
		$("#userlist").empty();
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
	});
	function userlist(pageNumber){
		$.getJSON("/allot_log/list?token=#(session.token??)&page="+pageNumber+"&size=12", function(userli) {
			console.log(userli);
			$("#total_users").html(userli.data.page.totalRow);
			totalPage = userli.data.page.totalPage;
			$("#userlist6").html(totalPage);
			$.each(userli.data.page.list, function(i, item){ 
				var userlist = {creater_real_name:item.creater_real_name,create_time:item.create_time,agents_real_name:item.agents_real_name,id:item.id};
				$("#userlistall").tmpl(userlist).appendTo('#userlist');
			});
		});	
	}
	
});
</script>
</body>
</html>

